const express = require('express');
const bodyParser = require('body-parser');

const day001 = express();
day001.use(bodyParser.json());

// GET请求处理
day001.get('/api/data', (req, res) => {
    // 处理GET请求逻辑
    res.json({ message: 'GET请求成功！' });
});

// POST请求处理
day001.post('/api/data', (req, res) => {
    // 处理POST请求逻辑
    const data = req.body;
    res.json({ message: 'POST请求成功！', data });
});

// PUT请求处理
day001.put('/api/data/:id', (req, res) => {
    // 处理PUT请求逻辑
    const id = req.params.id;
    const data = req.body;
    res.json({ message: `ID为${id}的数据已更新！`, data });
});

// PATCH请求处理
day001.patch('/api/data/:id', (req, res) => {
    // 处理PATCH请求逻辑
    const id = req.params.id;
    const data = req.body;
    res.json({ message: `ID为${id}的数据已部分更新！`, data });
});

// 启动服务器
day001.listen(3000, () => {
    console.log('服务器已启动，监听端口3000...');
});